<?php
// No directAcces
defined('_AppBackMiage') or die('Restricted access');

include_once (DS . "backoffice/include/header.php");

if(!isset($_GET['statutOffre'])){
    $statut = "en attente";
}
else {
    $statut = $_GET['statutOffre'];
}
?>
<div id="wrapper">
    <div id="content">
        <div id="rightnow">
            <?php
            $title = "offre de stage";
            $add = '<a class="add" href="' . URL . 'index.php?m=admin_offres_add">Ajouter une offre</a>';
            ?>

            <h3 class="reallynow">
                <span>Liste des <?php echo $title; ?></span>
                <?php echo $add; ?>
                <br />
            </h3>

            <form action="<?php echo URL; ?>index.php" method="get">
                <input type="hidden" name="m" value="admin_offres"/>
                <label for="statutOffre">Statut de l'offre : </label>
                <select name="statutOffre">
                    <option value="en attente" <?php if ($statut == "en attente")
                            echo "selected='selected' "; ?>>En attente</option>
                    <option value="acceptee" <?php if ($statut == "acceptee")
                            echo "selected='selected' "; ?>>Valid&eacute;e</option>
                    <option value="convoitee" <?php if ($statut == "convoitee")
                            echo "selected='selected' "; ?>>Convoit&eacute;e</option>
                    <option value="expiree" <?php if ($statut == "expiree")
                            echo "selected='selected' "; ?>>Expir&eacute;e</option>
                    <option value="refusee" <?php if ($statut == "refusee")
                            echo "selected='selected' "; ?>>Refus&eacute;e</option>
                </select>
                <input type="submit" value="Rechercher"/>
            </form>


                <?php
                /*                 * ***************** Variables pour la pagination ********************* */
                $nbrResultPerPage = 10;

                if (isset($_GET['page']) && !empty($_GET['page'])) {
                    $page = $_GET['page'];
                    $nbr = (((int) $_GET['page'] - 1) * $nbrResultPerPage);
                    $listOffres = Offre::getListOffre($nbrResultPerPage, $nbr, $statut);
                } else {
                    $page = 1;
                    $listOffres = Offre::getListOffre($nbrResultPerPage, 0, $statut);
                } 

                $count = Offre::globalCount($statut);
                $pages = ceil($count / $nbrResultPerPage);
                $pageSuivante = $page + 1;
                $pagePrecendente = $page - 1;
                if (!empty($listOffres)) {
                ?>
                <table width="100%">
                    <thead>
                        <tr>
                            <th>Titre de l'offre</th>
                            <th>Nom de l'entreprise</th>
                            <th>Promo</th>
                            <th>Action</th>

                        </tr>
                    </thead>
                    <tbody>
                    <?php
                    foreach ($listOffres as $o) {
                        $monOffre = new Offre($o->IdOffre);
                        $listIdsPromo = $monOffre->getIdsPromo();
                        $contactEntreprise = new ContactEntreprise($monOffre->getIdContactEntreprise());
                        $entreprise = new Entreprise($contactEntreprise->getIdEntreprise());
                        $editURL = URL . "/index.php?m=admin_offres_edit&oid=" . $monOffre->getIdOffre();
                    ?>
                        <tr>
                            <td><?php echo stripslashes($monOffre->getTitreOffre()); ?></td>
                            <td><?php echo stripslashes($entreprise->getNomEntreprise()); ?></td>
                            <td class="a-center"><?php
                                foreach ($listIdsPromo as $p) {
                                   $promo = new Promo($p);
                                   echo $promo->getNom()." ";
                                }
                                ?>
                            </td>
                            <td class="a-center">
                                <a href="<?php echo $editURL; ?>">
                                    <img alt="Editer offre"src="<?php echo STYLEBK; ?>img/icons/page_white_edit.png" title="Editer offre" width="16" height="16" />
                                </a>
                            </td>
                    </tr>
                    <?php
                        }
                    ?>
                    </tbody>
                </table>

                <div id="pager">
                    Page
                <?php if ($pagePrecendente > 0): ?>
                            <a href="<?php echo URL . "/index.php?m=admin_offres&page=" . $pagePrecendente; ?>&statutOffre=<?php echo $statut; ?>"><img src="<?php echo STYLEBK; ?>img/icons/arrow_left.gif" width="16" height="16" /></a>
                <?php endif; ?>
                <?php echo $page; ?>
                <?php if ($pageSuivante <= $pages): ?>
                                <a href="<?php echo URL . "/index.php?m=admin_offres&page=" . $pageSuivante; ?>&statutOffre=<?php echo $statut; ?>"><img src="<?php echo STYLEBK; ?>img/icons/arrow_right.gif" width="16" height="16" /></a>
                <?php endif; ?>
                                sur <?php echo $pages; ?> | Total <strong><?php echo $count; ?></strong> offres trouv&eacute;es
                            </div>

                <?php
                            }
                            else {
                                echo "Il n'y a pas d'offre.";
                            }
                ?>

                        </div>
                    </div>
<?php
include_once (DS . "backoffice/include/sidebar.php");
include_once (DS . "backoffice/include/footer.php");
?>
 